package com.bub.pay.framework.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

	@Bean
    public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory factory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(factory);
        RedisSerializer<String> redisSerializer = new StringRedisSerializer();// Long类型不可以会出现异常信息;
        redisTemplate.setKeySerializer(redisSerializer);
        redisTemplate.setHashKeySerializer(redisSerializer);

        JdkSerializationRedisSerializer redisSerializer2 = new JdkSerializationRedisSerializer();
        redisTemplate.setValueSerializer(redisSerializer2);
        redisTemplate.setHashValueSerializer(redisSerializer2);
        return redisTemplate;
    }
    
    @Bean(name = "smsTopic")
	public ChannelTopic smsTopic() {
		return new ChannelTopic("bub-client-top-sms");
	}

    @Bean(name = "emailTopic")
  	public ChannelTopic emailTopic() {
  		return new ChannelTopic("bub-client-top-email");
  	}
    
    @Bean(name = "clientTopic")
  	public ChannelTopic clientTopic() {
  		return new ChannelTopic("bub-client-top-http");
  	}
    
    @Bean(name = "callBackTopic")
  	public ChannelTopic callBackTopic() {
  		return new ChannelTopic("bub-client-top-callback");
  	}

    @Bean(name = "jPushTopic")
    public ChannelTopic jPushTopic(){
        return new ChannelTopic("bub-client-top-jPush");
    }
}
